<?php

class Halaman{

	var $db;

	public function __construct(){
		$this->db = new DBClass();
	}
	
	public function get_all_halaman(){
		
		$query = "SELECT * fROM log_activity_halaman l JOIN user u ON l.user_id_user = u.id_user 
		JOIN halaman h ON l.halaman_id_halaman = h.id_halaman";
		$rows = $this->db->getRows($query);
		return $rows;	
	}

	public function addHalaman($data){
		
		$query ="INSERT INTO halaman SET jdl_halaman='".@$data['jdl_halaman']."',
		isi_halaman='".@$data['isi_halaman']."',tgl_rilis='".date('Y-m-d')."'";
		$rows = $this->db->putRows($query);

		$lastID = $this->db->insertId();

		$query ="INSERT INTO log_activity_halaman SET halaman_id_halaman='".$lastID."',
		datetime_activity='".date('Y-m-d')."',
		user_id_user='".@$_COOKIE['c_id_user']."',
		jenis_activity='Tambah Halaman'";
		$rows = $this->db->putRows($query);

		header('Location: halaman.php');
	}

	public function deleteHalaman($data){
		
		$query ="DELETE FROM halaman WHERE id_halaman='".@$data."'";
		$rows = $this->db->putRows($query);
		header('Location: halaman.php');
	}

	public function updateHalaman($data){
		
		$query ="UPDATE halaman SET halaman_id_halaman='".$lastID."',
		datetime_activity='".date('Y-m-d')."',
		user_id_user='".@$_COOKIE['c_id_user']."',
		jenis_activity='Edit Halaman' WHERE id_halaman='".@$data."'" ;
		$rows = $this->db->putRows($query);
		header('Location: halaman.php');
	}

}